package com.example.play.model

import com.bawei.common.entity.SimpleVideoEntity
import com.example.common.model.BaseRepository
import com.example.play.api.PlayServerApi
import kotlinx.coroutines.flow.Flow
import kotlinx.coroutines.flow.flow

import javax.inject.Inject

class PlayRepository @Inject constructor(private val apiServer: PlayServerApi):BaseRepository<PlayServerApi>(){

    suspend fun getSimpleVideoByChannelId(channelId:String,page:Int,pageSize:Int): Flow<List<SimpleVideoEntity>> {
        return flow {
            val (code,data,msg)=apiServer.getSimpleVideoByChannelId(channelId,page,pageSize)
            if(code == 0){
                emit(data)
            }else{
                emit(listOf())
            }
        }
    }


    suspend fun getRecommendVideo(page: Int,pageSize: Int):Flow<List<SimpleVideoEntity>>{
        return flow {
            var (code,data,msg) = apiServer.getRecommendSimpleVideo(page,pageSize)
            if(code == 0){
                emit(data)
            }else{
                emit(listOf())
            }
        }
    }



}